package com.efuture.collection;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
 * @ClassNAME ArrayListTest
 * @Description ArrayList的基本用法
 * @Author zhaoshanshan
 * @Date 2021/9/7 5:00 下午
 * @Version 1.0
 */
public class ArrayListTest {

    public static void main(String[] args) {
        //创建对象
        List arrayList = new ArrayList();
        //添加元素
        arrayList.add(1);
        arrayList.add("123");
        arrayList.add(true);
        arrayList.add(new Test());
        //取出元素
        System.out.println(arrayList.get(0));
        System.out.println(arrayList.get(1));
        System.out.println(arrayList.get(2));
        System.out.println(arrayList.get(3));
        System.out.println("=========================");
        //遍历元素
        for(int i=0;i<arrayList.size();i++){
            System.out.println(arrayList.get(i));
        }
        System.out.println("=========================");
        for(Object obj:arrayList){
            System.out.println(obj);
        }
        System.out.println("=========================");
        Iterator it = arrayList.iterator();
        while (it.hasNext()){
            Object obj = it.next();
            System.out.println(obj);
        }

    }
}
class Test{

}